{% sw_extends '@Storefront/storefront/layout/meta.html.twig' %}

{% block layout_head_meta_tags_opengraph %}
    <meta property="og:type"
          content="product">
    <meta property="og:site_name"
          content="{{ config('core.basicInformation.shopName') }}">
    <meta property="og:url"
          content="{{ seoUrl('frontend.detail.page', { productId: page.product.id }) }}">
    <meta property="og:title"
          content="{{ metaTitle }}">

    <meta property="og:description"
          content="{{ metaDescription }}">
    <meta property="og:{{ page.product.cover.media.getMediaType().getName() === 'VIDEO' ? 'video' : 'image' }}"
          content="{{ page.product.cover.media.url }}">

    {% if page.product.manufacturer %}
        <meta property="product:brand"
              content="{{ page.product.manufacturer.translated.name }}">
    {% endif %}

    {% set metaPrice = page.product.calculatedPrice %}
    {% if page.product.calculatedPrices.count > 0 %}
        {% set metaPrice = page.product.calculatedPrices.last %}
    {% endif %}
    <meta property="product:price:amount"
          content="{{ metaPrice.unitPrice|round(context.currency.itemRounding.decimals) }}">
    <meta property="product:price:currency"
          content="{{ context.currency.isoCode }}">
    <meta property="product:product_link"
          content="{{ seoUrl('frontend.detail.page', { productId: page.product.id }) }}">

    <meta name="twitter:card"
          content="product">
    <meta name="twitter:site"
          content="{{ config('core.basicInformation.shopName') }}">
    <meta name="twitter:title"
          content="{{ metaTitle }}">
    <meta name="twitter:description"
          content="{{ metaDescription }}">
    <meta name="twitter:image"
          content="{{ page.product.cover.media.url }}">
{% endblock %}

{% block layout_head_title_inner %}
    {% if page.metaInformation.metaTitle %}{{ page.metaInformation.metaTitle }}{% else %}{{ page.product.translated.name }}{% if page.product.variation %} - {% for variation in page.product.variation %}{{ variation.group }}: {{ variation.option }}{% if page.product.variation|last != variation %}{{ ' | ' }}{% endif %}{% endfor %}{% endif %}{% endif %}
{% endblock %}

{% block layout_head_canonical %}
    {% set canonicalUrl = page.product.id %}

    {% if page.product.canonicalProductId %}
        {% set canonicalUrl = page.product.canonicalProductId %}
    {% endif %}

    <link rel="canonical" href="{{ seoUrl('frontend.detail.page', { productId: canonicalUrl }) }}">
{% endblock %}
